<template>
	<view class="club_deta_buy">
		<uv-navbar placeholder autoBack bgColor="#CA1C1D">
			<template v-slot:left>
				<view class="left_slot">
					<image src="@/static/images/back.png"></image>
				</view>
			</template>
			<template v-slot:center>
				<view class="nav_title">商品详情</view>
			</template>
			<!-- <template v-slot:right>
				<view class="right_slot">
					<image src="@/static/images/fx.png"></image>
				</view>
			</template> -->
		</uv-navbar>
		<scroll-view scroll-y class="scroll_view">
			<uv-swiper :list="rotation" keyName="img" radius="0" imgMode="scaleToFill" height="375"></uv-swiper>
			<view class="info">
				<view class="name">{{data_info.product.name}}</view>
				<view class="synopsis">{{data_info.product.synopsis}}</view>
				<view class="price">
					<view class="unit">￥</view>
					<view class="value">{{data_info.price}}</view>
				</view>
			</view>
			<view class="title">商品详情</view>
			<view class="parse_view">
				<uv-parse :preview-img="false" :content="data_info.product.content"></uv-parse>
			</view>
		</scroll-view>
		<view class="footer">
			<view class="submit" @click="router(`/pages/club/club_confirm_order?id=${id}`)">立即参与</view>
		</view>
		<uv-popup ref="paymentRef" mode="bottom">
			<Payment @close="paymentRef.close()" @submit="submit" />
		</uv-popup>
	</view>
</template>

<script setup>
	import {
		underwriteInfo,
		underwritePlace,
		underwritePaymentNew
	} from "@/request/api";
	import Payment from "@/components/common/Payment.vue";
	import useBase from "@/hooks/useBase.js";
	import useWechat from "@/hooks/useWechat.js";
	const {
		router
	} = useBase();
	const {
		wxPay
	} = useWechat();
	import {
		ref,
		reactive,
		shallowRef
	} from "vue";
	import {
		onLoad,
		onUnload
	} from "@dcloudio/uni-app";

	const rotation = ref([]);
	const data_info = ref({
		id: "",
		price: 0.00,
		stock: 0,
		created_at: "",
		product: {
			name: "",
			synopsis: "",
			content: "",
		}
	});

	let order_id;
	const paymentRef = shallowRef();
	const submit = async (pay_mode) => {
		let {
			pay_data
		} = await underwritePaymentNew({
			pay_mode,
			id: order_id
		});
		if (pay_mode == 2) {
			uni.$uv.toast("操作成功");
			setTimeout(() => {
				uni.switchTab({
					url: '/pages/tabbar/my'
				})
			}, 1000);
			return false;
		};
		wxPay(pay_data, () => {
			uni.$uv.toast("操作成功");
			setTimeout(() => {
				uni.switchTab({
					url: '/pages/tabbar/my'
				})
			}, 1000);
		});
	};
	let id;
	onLoad(async (options) => {
		id = options.id;
		let {
			data
		} = await underwriteInfo({
			id
		});
		data_info.value = data;
		rotation.value = data.product.imgs;
	});
	// onLoad(async ({
	// 	id
	// }) => {
	// 	let {
	// 		data
	// 	} = await underwriteInfo({
	// 		id
	// 	});
	// 	data_info.value = data;
	// 	rotation.value = data.product.imgs;
	// });
	onUnload(() => paymentRef.value.close());
</script>

<style scoped lang="scss">
	.club_deta_buy {
		min-height: calc(100vh - var(--window-top) - var(--window-bottom));
		background-color: #f5f5f5;

		.left_slot {
			image {
				width: 43rpx;
				height: 36rpx;
			}
		}

		.nav_title {
			color: #F5F5F5;
			font-size: 36rpx;
		}

		.right_slot {
			image {
				width: 32rpx;
				height: 32rpx;
			}
		}

		.scroll_view {
			height: calc(100vh - var(--window-top) - #{$navBarHeight} - var(--window-bottom) - 100rpx);

			.info {
				height: 285rpx;
				background: #FFFFFF;
				padding: 36rpx 56rpx 54rpx 42rpx;
				box-sizing: border-box;
				display: flex;
				flex-direction: column;
				justify-content: space-between;

				.name {
					line-height: 36rpx;
					color: #333333;
					font-size: 30rpx;
					font-weight: bold;
					overflow: hidden;
					text-overflow: ellipsis;
					display: -webkit-box;
					-webkit-line-clamp: 2;
					-webkit-box-orient: vertical;
				}

				.synopsis {
					color: #999999;
					font-size: 24rpx;
				}

				.price {
					display: flex;
					align-items: flex-end;

					.unit {
						color: #CA1C1D;
						font-size: 32rpx;
						font-weight: bold;
					}

					.value {
						color: #CA1C1D;
						font-size: 50rpx;
						font-weight: bold;
					}
				}
			}


			.title {
				height: 94rpx;
				line-height: 94rpx;
				color: #333333;
				font-size: 36rpx;
				font-weight: bold;
				padding-left: 40rpx;
				box-sizing: border-box;
				background: #FFFFFF;
			}

			.parse_view {
				background: #FFFFFF;
				// line-height: 48rpx !important;
				// color: #999999;
				// font-size: 28rpx;
				// padding: 30rpx;
				// box-sizing: border-box;
			}
		}

		.footer {
			height: 100rpx;
			padding: 0 30rpx;
			box-sizing: border-box;
			background-color: #FFFFFF;
			display: flex;
			align-items: center;

			.submit {
				width: 100%;
				height: 72rpx;
				line-height: 72rpx;
				text-align: center;
				color: #FFFFFF;
				font-size: 26rpx;
				border: none;
				background: #683617;
				border-radius: 10rpx;
			}
		}
	}
</style>